import random
import string


def generate_test_cases():
    test_cases = []

    # 测试用例1：简单案例
    test_cases.append(
        {
            "dictionary": ["hello", "leetcode"],
            "search_words": ["hello", "hhllo", "hell", "leetcoded"],
            "expected": [False, True, False, False],
        }
    )

    # 测试用例2：随机生成
    words = [
        "".join(random.choices(string.ascii_lowercase, k=random.randint(3, 8)))
        for _ in range(20)
    ]
    search_words = [
        "".join(random.choices(string.ascii_lowercase, k=random.randint(3, 8)))
        for _ in range(10)
    ]
    expected = []
    magic_dict = MagicDictionary()
    magic_dict.buildDict(words)
    for word in search_words:
        found = False
        for dict_word in words:
            if len(dict_word) == len(word):
                diff = sum(1 for a, b in zip(dict_word, word) if a != b)
                if diff == 1:
                    found = True
                    break
        expected.append(found)

    test_cases.append(
        {"dictionary": words, "search_words": search_words, "expected": expected}
    )

    return test_cases


if __name__ == "__main__":
    from alg import MagicDictionary

    test_cases = generate_test_cases()
    with open("test.py", "w") as f:
        f.write("test_cases = " + repr(test_cases))
